package com.maverick.guardianangel;



import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ImageSending extends Activity {
	ProgressBar bar;
	 TextView txt;
	 int total=0;
	 boolean isRunning=false;
	 // handler for the background updating
	 Handler handler=new Handler() {
	 @Override
	 public void handleMessage(Message msg) {
	 total=total+5;
	 if(total == 100)
	 {
		 txt.setText("Sent");
	 }
	 else
	 {
	 String perc=String.valueOf(total).toString();
	 txt.setText(perc+"% completed");
	 bar.incrementProgressBy(5);
	 
	 //txt.setText("Sent");
	 }
	 
	 }
	 };
	@Override
	public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.progressbar_activity);
	bar=(ProgressBar)findViewById(R.id.progress);
	 txt=(TextView)findViewById(R.id.txt);
	}
	public void onStart() {
	 super.onStart();
	 // reset the bar to the default value of 0
	 bar.setProgress(0);
	  // create a thread for updating the progress bar
	 Thread background=new Thread(new Runnable() {
	 public void run() {
	 try {
	 for (int i=0;i<20 && isRunning;i++) {
	 // wait 1000ms between each update
	 Thread.sleep(1000);
	 handler.sendMessage(handler.obtainMessage());
	 }
	 }
	 catch (Throwable t) {
	   }     }     });
	 isRunning=true;
	  // start the background thread
	 background.start();
	 }
	 public void onStop() {
	 super.onStop();
	 isRunning=false;
	 
	 }
	}